package main.flex.utils.calendar
{
	import mx.formatters.DateFormatter;
	
	public class DateFormatUtils
	{
		public static function convert( val : Object ) : Date
		{
	        if (val is String)
	        {
	            //If the incoming string is blank return null
	            if ( val == '' || val == null ) return null;
	
	            //Otherwise convert string from UTC to LocalTime
	            var df : DateFormatter = new DateFormatter();
	
	            df.formatString = "MM/DD/YYYY LL:NN:SS A";
	
	            var date : Date = new Date( df.format( val ) );
	
	            //offsetMilliseconds is the difference in Milliseconds between the users
	            //local time and the time sent into this function
	
	            var offsetMilliseconds : Number = date.getTimezoneOffset() * 60 * 1000;
	            return new Date( date.getTime() + offsetMilliseconds );
	        }
	        else if (val is Date)
	        {
	            return val as Date;
	        }
	        else return null;
	    }
	}
}